Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autoflake in precommit check #11619

Closed

Conversation

shweta83
Copy link
Contributor

@shweta83 shweta83 commented Jun 7, 2023

Why do we need it? Existing pre-commit checks doesn't remove unused imports and variables from the code. With autoflake, it remove these unused imports and variables in-place and avoids the manual effort.

@shweta83 shweta83 force-pushed the add_autoflake_precommit branch from 1e78130 to f50ba88 Compare June 7, 2023 10:51
@shweta83 shweta83 added 6.11.z Introduced in or relating directly to Satellite 6.11 CherryPick PR needs CherryPick to previous branches 6.12.z Introduced in or relating directly to Satellite 6.12 AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing 6.13.z Introduced in or relating directly to Satellite 6.13 6.14.z Introduced in or relating directly to Satellite 6.14 labels Jun 7, 2023
@shweta83 shweta83 requested review from jyejare and a team June 7, 2023 10:53
@adarshdubey-star
Copy link
Contributor

Can you take a look at the checks once

Comment on lines +37 to +40
- "--expand-star-imports"
- "--remove-duplicate-keys"
- "--remove-unused-variables"
- "--remove-all-unused-imports"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try configuring autoflake in pyproject.toml instead?

Copy link
Member

@jyejare jyejare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In CI chcks, One of the autoflake plugin trying to remove pass keyword from code which is not necessary to remove as they are placeholders and required to function the functions properly !

Please rectify the issue!

@ogajduse
Copy link
Member

In CI chcks, One of the autoflake plugin trying to remove pass keyword from code which is not necessary to remove as they are placeholders and required to function the functions properly !

Please rectify the issue!

There is nothing to rectify @jyejare.
Autoflake is correct, you do not have to have pass present in the function body if the function has a docstring.
I do not feel that this is a reason to block this PR.

@jyejare
Copy link
Member

jyejare commented Jun 22, 2023

Agree but using pass is a common behavior in programmers and that also tells it is not implemented.

I really dont see we should have any checks to remove it. Probably we can ignore that check from the hook.

@ogajduse
Copy link
Member

Agree but using pass is a common behavior in programmers and that also tells it is not implemented.

I really dont see we should have any checks to remove it. Probably we can ignore that check from the hook.

Agreed, using pass is a common habit, but that does not mean that we have to necessarily follow it.

PEP 257 states

A docstring is a string literal that occurs as the first statement in a module, function, class, or method definition. Such a docstring becomes the doc special attribute of that object.

That means that if the function has __doc__ defined, you do not have to explicitly state that the function is no-op by adding pass statement.

Also, pass does not tell you that the function is not implemented. We rather use the NotImplementedError exception for such cases. If the function is to be implemented, we should rather use Ellipsis.

There is a nice thread on this topic on Stack Overflow.

Since autoflake is developed by PyCQA, I would trust them and go with what their tools suggest.

@jyejare
Copy link
Member

jyejare commented Jun 23, 2023

@ogajduse Sure! And thanks for the nice explanation! Well still I will keep my NACK to fix the files which has pass statement in them and to pass the checks !

@ogajduse ogajduse requested review from a team July 4, 2023 19:11
@jyejare
Copy link
Member

jyejare commented Jul 5, 2023

@ogajduse @shweta83 The failing checks are still needed to be fixed in this PR else it will fail for all other PRs post merge!

@ogajduse
Copy link
Member

@lhellebr
Copy link
Contributor

About pass vs ..., this sums it up quite nicely: https://stackoverflow.com/questions/55274977/when-is-the-usage-of-the-python-ellipsis-to-be-preferred-over-pass
@ogajduse , why do you think "If the function is to be implemented, we should rather use Ellipsis."? I don't agree with that one.
OTOH, I do agree that we should use NotImplementedError more.

@ogajduse
Copy link
Member

@lhellebr I perhaps did not study it deeper. I do not have a strong opinion on whether to use Ellipsis or pass

@github-actions
Copy link

github-actions bot commented Sep 9, 2023

This pull request has not been updated in the past 45 days.

@github-actions github-actions bot added the Stale Stale issue or Pull Request label Sep 9, 2023
@lhellebr
Copy link
Contributor

What's the status here? From reading the comments, I wasn't able to identify what's blocking progress. Are we waiting for @shweta83 to fix the style checks?

@ogajduse
Copy link
Member

I am in favor of closing this PR as there is a plan to include ruff into our workflow in robottelo in the same way as in broker, nailgun, and airgun.

@github-actions github-actions bot removed the Stale Stale issue or Pull Request label Sep 13, 2023
@ogajduse
Copy link
Member

Ruff added as a part of #12621

@jyejare
Copy link
Member

jyejare commented Oct 3, 2023

@shweta83 We should now close this as we have ruff in place now!

Thanks for all your efforts though 👍

@jyejare jyejare closed this Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.11.z Introduced in or relating directly to Satellite 6.11 6.12.z Introduced in or relating directly to Satellite 6.12 6.13.z Introduced in or relating directly to Satellite 6.13 6.14.z Introduced in or relating directly to Satellite 6.14 AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing CherryPick PR needs CherryPick to previous branches
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants